import type {PageInfo} from "plus-pro-components";
import type {StoreSearchParam} from "../model/store.ts";
import {commonQuery} from "./query.ts";


/**
 * 获取药店列表
 * @param params - 分页和筛选参数
 * @returns 药店列表
 */
export const getStores = async (params: Partial<PageInfo> & StoreSearchParam) => {
    let newVar = await commonQuery<any>('stores', {
        page: params.page,
        page_size: params.pageSize,
        distinct: true,
        order_by: [
            {
                field: 'brand',
            },
            {
                field: 'district',
            },
            {
                field: 'name',
            },
        ],
        where: [
            {
                field: 'brand',
                operator: 'in',
                value: params.brand || []
            },
            {
                field: 'sales_rep',
                operator: 'in',
                value: params.sales_rep
            },
            {
                field: 'sales_rep',
                operator: 'in',
                value: params.sales_rep
            }, {
                field: 'district',
                operator: 'in',
                value: params.region.map(r => r[1])
            }
        ]
    });
    newVar.forEach((item) => {item.brand = item.brand + ''});
    return newVar;
};